<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\controllers',
    'bootstrap' => ['log'],
    'modules' => [
        'gridview' =>  [
            'class' => '\kartik\grid\Module'    //此扩展使用于 kartik-v/yii2-grid ，故在此之前必须使用 gridview module
        ]
    ],
    'components' => [
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 2,
            'password'  => 'B7dHr2',
        ],
        'PayToUser' => [
            'class' => 'api\components\PayToUser',
        ],
        'PaysToUser' => [
            'class' => 'api\components\PaysToUser',
        ],
        'WeChatPublic' => [
            'class' => 'api\components\WeChatPublic',
        ],
        'PaysRed' => [
            'class' => 'api\components\PaysRed',
        ],
//        'request' => [
//            'parsers' => [
//                'application/json' => 'yii\web\JsonParser',
//            ]
//        ],
//        'response' => [
//            'class' => 'yii\web\Response',
//            'on beforeSend' => function ($event) {
//                $response = $event->sender;
//                $response->data = [
//                    'status' => 200,
//                    'desc' => $response->statusText,
//                    'data' => $response->data,
//                    't' => time(),
//                ];
//                $response->statusCode = $response->getStatusCode();
//            },
//        ],

        'user' => [
            'identityClass' => 'backend\models\User',
            'enableAutoLogin' => true,
            'enableSession' => false,
            'loginUrl' => null,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
//        'errorHandler' => [
//            'errorAction' => 'site/error',
//        ],
        /*
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        */
        'urlManager' => [
            'enablePrettyUrl' => true,
//            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => 'wechat',
                    'extraPatterns' => [
                        'GET valid' => 'valid',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => 'user',
                    'except' => ['delete', 'create', 'update'],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => 'order',
                    'except' => ['delete', 'create', 'update','get'],
                ],
            ],
        ],
    ],
    'params' => $params,
];
